<?php
  /**
 * @version        $Id: moduletemplate.php 478 2010-06-16 16:11:42Z joomlaworks $
 * @package        K2
 * @author        JoomlaWorks http://www.joomlaworks.gr
 * @copyright    Copyright (c) 2006 - 2010 JoomlaWorks, a business unit of Nuevvo Webware Ltd. All rights reserved.
 * @license        GNU/GPL license: http://www.gnu.org/copyleft/gpl.html
 */

// no direct access
defined('_JEXEC') or die('Restricted access');

class JElementMultiFeild extends JElement
{
     var $_name = 'multifeild';

    function fetchElement($name, $value, &$node, $control_name) {
        $lang = JFactory::getLanguage();
        $lang->load('mod_jvtextslide');
        $value = JText::_($value);
        
        JVLib::import('javascript');
        $doc = JFactory::getDocument();
        $doc->addStyleSheet(JURI::root(true).'/modules/mod_jvslideshow/element/multifeild.css');
        $option = $node->attributes('options');
        $option = $option?$option:'{}';
        $feildOption = $node->attributes('feildoptions');
        $feildOption = $feildOption?$feildOption:'{}';
        $doc->addScriptdeclaration('
                j.using("JVLib.CustomField").ready(function(){
                    var f = {};
                    f.element = $$("[name*='.$name.']")[0];
                    f.MultiObj = new J.MultiField('.$option.','.$feildOption.',JSON.parse(f.element.value));
                    f.element.after(f.MultiObj);
                    var submit = window.submitbutton;
                    window.submitbutton = function() {
                        f.element.value = JSON.stringify(f.MultiObj.data());
                        submit.apply(window,arguments);
                    }
                });
        ');
        
        $name = "{$control_name}[{$name}]";
        return '<textarea style="display:none" name="'.$name.'">'.$value.'</textarea>';
    }
    function fetchTooltip(){
        return '';
    }
}
?>